package demo.springboot.Controller;

import demo.springboot.POJO.T_news;
import demo.springboot.service.T_newsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

// Created by bysocket on 30/09/2017
@Controller
@RequestMapping(value = "/ajaxtest")
public class Ajax_Test {

    @Autowired
    T_newsService newsService;

    @GetMapping(value = "")
    public String getBookList( Model model) {
        List<T_news> all = newsService.findAll();
        System.out.println(all);
        model.addAttribute("all_news", "张三");
        return "ajaxtest.html";
    }



    @GetMapping(value = "/json")
    @ResponseBody
    public List<T_news> testttt(Model model) {
        List<T_news> all = newsService.findAll();
        model.addAttribute("news", all);
        return all;
    }


}
